[C#] foreach loop corrent index
Posted
by
Eyla
on Stack Overflow
See other posts from Stack Overflow
or by Eyla
Published on 2011-01-01T22:41:00Z
Indexed on
2011/01/01
22:53 UTC
Read the original article
Hit count: 253
Is there anyway to know the current run of a foreach without have to:
Int32 i;
foreach
i++;
or is that the best option i got?? Also, how can i know the maximum number of items on that loop?? What i am trying to do is update a progressbar during a foreach loop on my form
Thanks
This is what i got
foreach (FileInfo file in DirectoryFiles)
{
if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden || (file.Attributes & FileAttributes.System) == FileAttributes.System)
continue;
backgroundWorkerLoadDir.ReportProgress(i, file.Name);
System.Threading.Thread.Sleep(10);
}
© Stack Overflow or respective owner